/*
 * File:   ReaderTest.cpp
 * Author: Guilherme Monteiro
 *
 */

#include "ReaderTest.h"


CPPUNIT_TEST_SUITE_REGISTRATION(ReaderTest);

ReaderTest::ReaderTest() {
}

ReaderTest::~ReaderTest() {
}

void ReaderTest::setUp() {
}

void ReaderTest::tearDown() {
}

void ReaderTest::testReader1() {
    string highTablePath = "";
    
    try {
        Reader* reader = new Reader(highTablePath);
    }
    catch(InvalidFileException ife) {
        string message = "ERROR ==> Invalid file: " + highTablePath;
        if (strcmp(message.c_str(), ife.what()) != 0) {
             CPPUNIT_ASSERT(false);
        }
    }
    catch(exception e) {
        CPPUNIT_ASSERT(false);
    }
}

void ReaderTest::testReader2() {
    string highTablePath = "/books";
    
    try {
        Reader* reader = new Reader(highTablePath);
    }
    catch(InvalidFileException ife) {
        string message = "ERROR ==> Invalid file: " + highTablePath;
        if (strcmp(message.c_str(), ife.what()) != 0) {
             CPPUNIT_ASSERT(false);
        }
    }
    catch(exception e) {
        CPPUNIT_ASSERT(false);
    }
}

void ReaderTest::testReadCells() {
    string fileExample = "../books/caracterizacao/metadados/respostaUsuarioTT/image278_0.txt";
    Reader* reader = new Reader(fileExample);
    vector<Cell> result = reader->readCells();
    
    if (result.size() != 66) {
        CPPUNIT_ASSERT(false);
    }
    
    if (result[0].leftUpper.x != 0 && result[0].leftUpper.y != 0) {
        CPPUNIT_ASSERT(false);
    }
    if (result[0].rightBottom.x != 39 && result[0].rightBottom.y != 38) {
        CPPUNIT_ASSERT(false);
    }
    
    if (result[7].leftUpper.x != 39 && result[7].leftUpper.y != 38) {
        CPPUNIT_ASSERT(false);
    }
    if (result[7].rightBottom.x != 440 && result[7].rightBottom.y != 112) {
        CPPUNIT_ASSERT(false);
    }
}

void ReaderTest::testReadPoints() {
    string fileExample = "../books/caracterizacao/metadados/respostaUsuarioTT/image278_0.txt";
    Reader* reader = new Reader(fileExample);
    vector<CvPoint> result = reader->readPoints();
    if (result.size() != 132) {
        CPPUNIT_ASSERT(false);
    }
}

